﻿using FarmSmartSleep.Common.Domain.BeginTable;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Organ.API.Application.Commands.EnterpriseCommands;
using FarmSmartSleep.Organ.API.Application.SleepInfoCommands.FemaleBeginCommands;
using FarmSmartSleep.Organ.API.Application.SleepInfoCommands.RecordCommands;
using FarmSmartSleep.Organ.API.Application.SleepInfoCommands.SelectRecord;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace FarmSmartSleep.Organ.API.Controllers
{
    /// <summary>
    /// 羊只初期管理 控制器--API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SleepBeginController : ControllerBase
    {
        public readonly IMediator mediator;

        public SleepBeginController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        #region 期初新增显示
        /// <summary>
        /// 种公新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("seedmaleAdd")]
        public async Task<Result> Handle(SeedmaleCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 种公显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("seedmaleList")]
        public async Task<Result> Handle(SeedmaleListCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 种母新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("AddFemaleBegin")]

        public async Task<Result> Handle(FemaleBeginCreateCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 种母显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("SelectFemaleBegin")]
        public async Task<Result> Handle(FemaleBeginSelectCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 后裔添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddProBegin(ProBeginCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 批量添加后裔期初
        /// </summary>
        /// <param name="cmd">批量添加后裔期初请求对象</param>
        /// <returns>批量添加后裔期初响应对象</returns>
        [HttpPost]
        public async Task<Result> AllAddProBegin(ProBeginAllCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 后裔显示（分页）
        /// </summary>
        /// <param name="cmd">后裔显示请求对象</param>
        /// <returns>返回后裔信息</returns>
        [HttpPost]
        public async Task<ResultPage<ProbeginDto>> SearchProBegin(ProBeginSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        #endregion
        #region 羊只档案
        /// <summary>
        /// 羊只档案列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultT<SleepRecordDto>> SearchSleepRecord()
        {
            return await mediator.Send(new SleepRecordSearchCommand());
        }
        /// <summary>
        /// 养只信息表添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("SheepInforAdd")]
        public async Task<Result> Handle(SheepInforCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 查询父母耳号
        /// </summary>
        /// <param name="mid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchCode(string code)
        {
            return await mediator.Send(new GetCodeCommand() { code = code });
        }
        /// <summary>
        /// 查询羊只信息（耳号档案）
        /// </summary>
        /// <param name="sleepInforId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultT<SleepRecordDto>> GetSleepInfo(int sleepInforId)
        {
            return await mediator.Send(new GetSleepInfoCommand() { sleepInforId = sleepInforId });
        }

        #endregion
        #region 下拉框
        /// <summary>
        /// 品种下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchVariety()
        {
            return await mediator.Send(new VarietySearchCommand());
        }
        /// <summary>
        /// 基因等级下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchGene()
        {
            return await mediator.Send(new GeneGradeSearchCommand());
        }
        /// <summary>
        /// 出生状态下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchBirth()
        {
            return await mediator.Send(new BirthStatuSearchCommand());
        }
        /// <summary>
        /// 羊只类型下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchSleepType()
        {
            return await mediator.Send(new SleepTypeSearchCommand());
        }
        /// <summary>
        /// 男性耳号下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SelectEarMale()
        {
            return await mediator.Send(new SheepInforTypeCommand());
        }
        /// <summary>
        /// 女性耳号下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SelectEarFeMale()
        {
            return await mediator.Send(new FamaleEarTypeCommand());
        }
        /// <summary>
        /// 耳号下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultT<List<SleepInfor>>> SelectEar()
        {
            return await mediator.Send(new EarCodeSelectCommand());
        }

        /// <summary>
        /// 获取后裔耳号信息方法
        /// </summary>
        /// <param name="cmd">获取后裔耳号信息方法请求对象</param>
        /// <returns>获取后裔耳号方法响应对象</returns>
        [HttpGet]
        public async Task<ResultT<SleepInfor>> ProBeginEarSearch([FromQuery]ProBeginEarSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        #endregion

    }
}
